package cn.jinjimi.app.plugin;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import cn.jinjimi.framework.plugin.BasePluginConfig;
import cn.jinjimi.framework.plugin.Plugin;
import cn.jinjimi.app.bean.BundleKey;
import cn.jinjimi.app.main.activity.WebActivity;

/**
 * Created by Hiro on 15/6/3.
 */
public class WebPluginLauncher extends SimplePluginLauncher {

    @Override
    public void launch(Context context, Plugin plugin) {
        if(plugin instanceof WebPlugin) {

            WebPlugin p = (WebPlugin) plugin;

            Intent intent = new Intent(context, WebActivity.class);

            intent.putExtra(PluginParam.PLUGIN_TITLE, p.getTitle());
            intent.putExtra(PluginParam.PLUGIN_CODE, p.getCode());
            intent.putExtra(PluginParam.PLUGIN_URL, p.getUrl());
            intent.putExtra(BundleKey.SOURCE,p.getF_source());

            BasePluginConfig config = p.getConfig();

            if(config!=null) {
                Bundle param = new Bundle();
                param.putInt(BasePluginConfig.PLUGIN_CONFIG_FLAG_SOURCE, config.source);
                intent.putExtra(PluginParam.PLUGIN_CONFIG, param);
            }

            context.startActivity(intent);
        }
    }
}
